<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5shiv.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css" />
<!--[if IE 6]>
<script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>运输管理</title>
<style>
	<style>
		  /* 整体设置 */
		  *{margin:5px;padding:5px;}
		   
		  /**
		   * 设置日历的大小
		   */
		  .calendar{
		 /*   width: 80%;
		    height: 60%;
		    display: block; */
			
		    position: absolute;      /*绝对定位*/
			/*top: 25%;                  /* 距顶部50%*/   
			/*left: 20%;                   距左边50%*/   
			/*height: 40%;    /*margin-top为height一半的负值*/   
			width:30%;    /*margin-left为width一半的负值*/  
			margin-top:0.9375rem;
		  }
		  
		  
		   
		  /**
		   * 设置日历顶部盒子
		   */
		  .calendar .calendar-title-box{
		    position: relative;
		    width: 100%;
		    height: 36px;
		    line-height: 36px;
		    text-align:center;
		    border-bottom: 1px solid #ddd;
		  }
		   
		  /**
		   * 设置上个月的按钮图标
		   */
		  .calendar .prev-month {
		    position: absolute;
		    top: 12px;
		    left: 0px;
		    display: inline-block;
		    width: 0px;
		    height: 0px;
		    border-left: 0px;
		    border-top: 6px solid transparent;
		    border-right: 8px solid #999;
		    border-bottom: 6px solid transparent;
		    cursor: pointer;
		  }
		   
		  /**
		   * 设置下个月的按钮图标
		   */
		  .calendar .next-month {
		    position: absolute;
		    top: 12px;
		    right: 0px;
		    display: inline-block;
		    width: 0px;
		    height: 0px;
		    border-right: 0px;
		    border-top: 6px solid transparent;
		    border-left: 8px solid #999;
		    border-bottom: 6px solid transparent;
		    cursor: pointer;
		  }
		   
		   
		  /* 设置日历表格样式 */
		  .calendar-table{
		    width: 100%;
		    border-collapse: collapse;
		    text-align:center;
		  }
		   
		  /* 表格行高 */
		  .calendar-table tr{
		    height: 30px;
		    line-height: 30px;
		  }
		   
		  /* 当前天 颜色特殊显示 */
		  .currentDay {
		    color: red;
		  }
		   
		  /* 本月 文字颜色 */
		  .currentMonth {
		    color: #999;
		  }
		  
		  /* 本月 取胆日期 */
		  .mohthGetCashbox {
		    color: red;
		  }
		  
		  /* 本月 取胆日期 */
		  .mohthGetCashbox2 {
		    color: red;
		  }
		   
		  /* 其他月颜色 */
		  .otherMonth{
		    color: #ede;
		  }
		  
		  .typeContent{
		    /*position: absolute;      /*绝对定位*/
			/*top: 75%;                  /* 距顶部50%*/   
			/*left: 10%;                  /* 距左边50%*/   
			height: 65px;    /*margin-top为height一半的负值*/   
			width: 85%;    /*margin-left为width一半的负值*/  
		  			
		   }
		   
		   .typeContentDiv{
				position: absolute;      /*绝对定位*/
				top: 70%;                  /* 距顶部50%*/   
				left: 10%;                  /* 距左边50%*/   
		    }
			
			.divSpan{
				text-align: left; 
				margin-left: 30%;
			 }
			
		 
	</style>
	
</style>
</head>
<body>
<div class="page-container" style="padding: 5px;" >
	
	<!--头部-->
	<div style="margin-top: 10px; text-align: center; height: 40px;">
		分公司:
		<span class="select-box inline">
			<select class="select" id="comId" name="comId">
				<option value="">请选择分公司</option>
			</select>
		</span>
		
		票务室:
		<span class="select-box inline">
			<select class="select" id="toId" name="toId">
				<option value="">请选择票务室</option>
			</select> 
		</span>
		<!-- 	$("#remarks").attr("style", "display:blank;"); -->
		<div style="display: none;" id="rallyingPointDiv">
			<span class="select-box inline">
				<select class="select" id="rallyingPoint" name="rallyingPoint">
					<option value="">请选择集结中心</option>
				</select> 
			</span>
		</div>
		
		网点类型:
		<span class="select-box inline">
			<select class="select" id="tickets" name="tickets">
				<option value="">请选择网点类型</option>
				<option value="1">纯有人售</option>
				<option value="2">混编售</option>
				<option value="3">纯无人售</option>
				<option value="4">充值点</option>
			</select> 
		</span>
	</div>
	
	<!--中间内容-->
	<div style="margin-top: 5px; height: 300px;">
		<div style="float:left; width: 45%; text-align: center; margin-left: 5%;">
			月份:
			<span class="select-box inline">
			<select class="select" id="queryMonth" name="queryMonth">
				<option value="">请选择月份</option>
			</select> 
			</span>
			<button name="" id="" onclick="queryTableLeft();" class="btn btn-success" type="submit"><i class="Hui-iconfont">&#xe665;</i>历史查询</button>
				<span style="font-size: 8px; color: red;">*历史数据参考</span>
			<div style="margin-left: 5%;" class='calendar' id='calendarLeft'>
				
			</div>
		</div>
		
		<div style="float: right; width: 45%; text-align: center; margin-right: 5%;">
			<div style="">
				 月份:
				<span class="select-box inline">
				<select class="select" id="month" name="month">
				<!-- 	<option value="">请选择月份</option> -->
				</select> 
				</span>
				<button name="" id="" onclick="saveTable();" class="btn btn-success" type="submit">
					<i class="Hui-iconfont">&#xe665;</i>保存
				</button>
				<span style="font-size: 8px; color: red;">*拟制定计划</span>
			</div>
			<div style="margin-left: 5%;" class='calendar' id='calendar'>
				
			</div>
		</div> 
	</div>
	<div id="divSpan" class="divSpan" style="display:none;" >
		<span>考虑到充值点钱胆流转讯速,制定计划时建议每天都选中。</span>
	</div>
	<!--备注-->
	<div style="text-align: left; margin-left: 10%;">
		<div style=" display:none; " id="remarks">
			<span>备注:</span>
		</div>
		<div>
			<textarea style="display:none;" class="typeContent" id="typeContent" >
			</textarea>
		</div>
	</div>
	
	<!--
	<footer style=" position: absolute;bottom: 50px;left: 45%;" class="mt-20">
		<input id="reg"  style=" display:none; "   class="btn btn-primary radius" onclick="regClickSubmit()" type="button" value="&nbsp;&nbsp;提交申请&nbsp;&nbsp;">
		<input id="reg2"  style=" display:none; "   class="btn btn-primary radius" onclick="regClickSubmit2()" type="button" value="&nbsp;&nbsp;保存&nbsp;&nbsp;">
		<input id="inputId1"  style=" display:none;"  class="btn btn-primary radius" onclick="regClick()"  type="button" value="&nbsp;&nbsp;通过&nbsp;&nbsp;">
		<input id="inputId2"  style=" display:none; " class="btn btn-primary radius" onclick="noRegClick()"  type="button" value="&nbsp;&nbsp;不通过&nbsp;&nbsp;">
	</footer>
	-->
</div>

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript" src="js/jquery.base64.js"></script>
<script type="text/javascript" src="js/workplan.js"></script>
<script type="text/javascript" src="js/vue.js" charset="utf-8"></script>
<script type="text/javascript">

$(function(){
		var comId;
		var toId;
		var userinfo =getUserInfo();//window.localStorage.getItem("userinfo");
		//var groups =userinfo.groups
		var username =userinfo.username;
		var myArray;
		
		$.ajax({
			type: 'get',
			url: report_service+'/getAllCompany',
			/* beforeSend: function (request) {
							request.setRequestHeader("Authorization", "Bearer " + getToken());
						}, */
			dataType: 'json',
			async: false,
			success: function(data){
				var list =  eval('(' + data.list + ')');
				for(var i = 0;i<list.length;i++){
					$("#comId").append("<option value='"+list[i].companyid+"'>"+list[i].companyname+"</option>");				
				}
			},
			error: function(data){
				console.log(data.msg);
			}
		});
		
		$.ajax({
			type: 'get',
			url: report_service+'/getUserByname',
			data:{
				"username": username
			},
			async: false,
			/* beforeSend: function (request) {
							request.setRequestHeader("Authorization", "Bearer " + getToken());
						}, */
			dataType: 'json',
			success: function(data){
				var list =  eval('(' + data.list + ')');
				if(list[0].officeId.indexOf("1")==0){
					$("#comId").val(list[0].companyId);
					comId = list[0].companyId;
					
					$.ajax({
						type: 'get',
						url: report_service+'/getTicktOfficeByCom',
						/* beforeSend: function (request) {
										request.setRequestHeader("Authorization", "Bearer " + getToken());
									}, */
						data:{
							"comId":comId
						},
						cache:false,    
						dataType:'json',
						async: false,
						success: function(data){
							
							var list =  eval('(' + data.list + ')');
							for(var i=0;i<list.length;i++){
								var option = '<option value="'+list[i].toiid+'">'+list[i].toiname+'</option>';
								$("#toId").append(option);
							}
						},
						error:function(){
							alert("请求失败");
						}
					});
					$("#toId").val(list[0].officeId);
					toId = list[0].officeId;
					$("#comId").attr("disabled","disabled");
					$("#toId").attr("disabled","disabled");
				}
				if(list[0].officeId.indexOf("1") == -1  && list[0].companyId.indexOf("1")==0 ){
					$("#comId").val(list[0].companyId);
					comId = list[0].companyId;
					$.ajax({
						type: 'get',
						url: report_service+'/getTicktOfficeByCom',
						/* beforeSend: function (request) {
										request.setRequestHeader("Authorization", "Bearer " + getToken());
									}, */
						data:{
							"comId":comId
						},
						cache:false,    
						dataType:'json',
						async: false,
						success: function(data){
									
							//var list = data.list;
							var list =  eval('(' + data.list + ')');
							for(var i=0;i<list.length;i++){
								var option = '<option value="'+list[i].toiid+'">'+list[i].toiname+'</option>';
								$("#toId").append(option);
							}
						},
						error:function(){
							alert("请求失败");
						}
					});
					$("#comId").attr("disabled","disabled");
				}
			},
			error: function(data){
				console.log(data.msg);
			}
		});
		
	//历史月份记录	
		$.ajax({
			type: 'get',
			url: reportForm+'workPlanTitle/getWorkPlanTitleAll',
			/* beforeSend: function (request) {
							request.setRequestHeader("Authorization", "Bearer " + getToken());
						}, */
			dataType: 'json',
			async: false,
			success: function(data){
				var list = data.workPlanTitle; //eval('(' + data.workPlanTitle + ')');
				for(var i = 0;i<list.length;i++){
					var titleName = list[i].titleName;
					console.log(titleName)
					titleName=titleName.substring(0,4)+"年"+titleName.substring(4,6)+"月";
					$("#queryMonth").append("<option value='"+list[i].titleName+"'>"+titleName+"</option>");				
				}
			},
			error: function(data){
				console.log(data.msg);
			}
		});
		
		
		
		
		
		 var _year =dateObj.getDate().getFullYear();
		 var _month = dateObj.getDate().getMonth() + 1+1;
		console.log("当前月"+_month)
		
		if(_month+6>12){
			for(var i = _month;i<=12;i++){
				console.log("长度====")
				if(i<10){
					$("#month").append("<option value='"+_year+"0"+i+"'>"+_year+"年0"+i+"月</option>");
				}else{
					$("#month").append("<option value='"+_year+i+"'>"+_year+"年"+i+"月</option>");
				}
			}
			var mon = _month+6-12
			_year=_year+1;
			for(var i =1;i<=mon;i++){
				if(i<10){
					$("#month").append("<option value='"+_year+"0"+i+"'>"+_year+"年0"+i+"月</option>");
				}else{
					$("#month").append("<option value='"+_year+i+"'>"+_year+"年"+i+"月</option>");
				}					
			}
			
		}else{
			for(var i = _month;i<=12;i++){
				if(i<10){
					$("#month").append("<option value='"+_year+"0"+i+"'>"+_year+"年0"+i+"月</option>");
				}else{
					$("#month").append("<option value='"+_year+i+"'>"+_year+"年"+i+"月</option>");
				}				
			}
		}
	
		//	$("#month").val(_month);
		// 	if(_month.indexOf("月")==1){
		// 	_month = _month.substr(0,1);
		// 	}
		// var day = new Date(_year,_month,0);  
		// titleNums = day.getDate()
		var titleName = _year+"年"+_month+"月";
		var companyId = $("#comId").val();
		var officeId = $("#toId").val();
		$("#calendar").empty();
		creationMonthRight(titleName);
		if(companyId!=null&&officeId!=null&&companyId!=""&&officeId!=""){
			queryTableLeft(titleName);
			//queryTable();
		}else{
		//	alert("请选择分公司和票务室")
		}

//queryCompany();
});
			

		$("#remarks").attr("style", "display:blank;");
		$("#typeContent").attr("style", "display:blank;");

		$("#month").change(function(){
			var titleName = $(this).val();
			$("#calendar").empty();
			creationMonthRight(titleName);
		});
		$("#tickets").change(function(){
			var titleName = $(this).val();
			$("#calendar").empty();
			creationMonthRight(titleName);
		}) 
		
		
			
	
	function queryTable(){
		var companyId = $("#comId").val();
		var officeId = $("#toId").val();
		var titleName = $("#queryMonth").val();
		if(companyId!=null&&officeId!=null&&companyId!=""&&officeId!=""){
			//console.log(companyId+"===="+officeId+"===="+serialNumber)
			if(titleName==null&&titleName==""){
				var _year =dateObj.getDate().getFullYear();
				var _month = dateObj.getDate().getMonth() + 1;
				titleName = _year+"年"+_month+"月";
			}
			console.log(titleName)
			$.ajax({
				type: 'post',
				url:reportForm+'workPlan/getWorkPlanByComAndOffAndSerialNumber',
				data: {
					companyId:companyId,
					officeId:officeId,
					//serialNumber:serialNumber,
					titleName:titleName
				},
				dataType: 'json',
				success: function(data){
					$("#calendar").empty();
					var workPlanTitle= data.workPlanList 
					creationMonth(workPlanTitle,titleName);
				},
				error:function(data) {
					console.log(data.msg);
				},
			});
		}else{
			alert("请选择公司和票务室")
		}
		

}

// function saveTable(){
// 	var companyId = $("#comId").val();
// 	var officeId = $("#toId").val();
// 	var titleName = $("#month").val();
	
//     $.ajax({
//     	type: 'post',
//     	url:reportForm+'workPlan/getWorkPlanByComAndOffAndSerialNumber',
//     	data: {
// 			companyId:companyId,
// 			officeId:officeId,
// 			//serialNumber:serialNumber,
// 			titleName:titleName
//     	},
//     	dataType: 'json',
//     	success: function(data){
// 			$("#calendar").empty();
// 			var workPlanTitle= data.workPlanList 
// 			creationMonth(workPlanTitle,titleName);
//     	},
//     	error:function(data) {
//     		console.log(data.msg);
//     	},
//     });

// }

function saveTable(){ //提交申请 
		var companyId = $("#comId").val();
		var officeId = $("#toId").val();
		var titleName = $("#month").val();
		var rallyingPoint = $("#rallyingPoint").val();
		var tickets = $("#tickets").val();
		if(companyId==""){
			alert("请选择公司");
			return;
		}
		if(officeId==""){
			alert("请选择票务室");
			return;
		}
		if(titleName==""){
			alert("请选择计划时间");
			return;
		}
		if(rallyingPoint==""){
			alert("请选择集结中心");
			return;
		}
		if(tickets==""){
			alert("请选择网点类型");
			return;
		}
	
		var saveTdHtml = document.getElementsByClassName("mohthGetCashbox");
	
		
		var all = "";
		var day0TdHtmlall = document.getElementsByClassName("all");
		
		for(var i = 0;i<day0TdHtmlall.length;i++){
			console.log(day0TdHtmlall[i].innerText)
			//不去
			all+=day0TdHtmlall[i].innerText+",";
		}
		console.log(all)
		var comId= $("#comId").innerHTML;
		var userinfo =getUserInfo();//window.localStorage.getItem("userinfo");
		var username = userinfo.username;
		var typeContent = document.getElementById("typeContent").value;
					layer.confirm('确认要提交？', function(index) {
	//  00 公司编辑
	//  01 集团审核
	//  02 物流审核    
	//  03 银行审核 
	//  04 发布      
	
	//  97 集团不通过
	//  98 物流不通过
	//  99 银行不通过
		$.ajax({
			type: 'post',
			url:reportForm+'workPlan/addTableWorkPlan',
			data: {
					titleName:titleName,
					companyId:companyId,
					officeId:officeId,
					ids:all,
					ids0:"",
					step:"01",
					username:username,
					rallyingPoint:rallyingPoint,
					tickets:tickets,
					typeContent:typeContent
			},
			dataType: 'json',
			success: function(data){
				var msg = 	data.msg;
				if (msg!="0") {
					layer.open({
						content: "成功！",
						title: '提交申请',
						yes: function(index, layero) {
							layer.close(index); //如果设定了yes回调，需进行手工关闭
							var index = parent.layer.getFrameIndex(window.name);
							parent.$('.btn-refresh').click();
							parent.layer.close(index);
						}
					});
					//
				} else {
					alert("提交失败")
				}
								
			},
			error:function(data) {
				console.log(data.msg);
			},
		 });
	});
		
}


 /*
	   * 用于记录日期，显示的时候，根据dateObj中的日期的年月显示
	   */
		var dateObj = (function(){
			var _date = new Date();    // 默认为当前系统时间
			return {
			  getDate : function(){
				return _date;
			  },
			  setDate : function(date) {
				_date = date;
			  }
			};
		  })();


	$("#comId").change(function(){
		$("#toId").empty();
		var comId = $(this).val();
		var targetUrl = report_service+'/getTicktOfficeByCom';
		if(comId == ''){
			//$("#toId").fadeOut("slow");
			return;
		}
		$.ajax({
			type: 'get',
			url: targetUrl,
			/* beforeSend: function (request) {
							request.setRequestHeader("Authorization", "Bearer " + getToken());
						}, */
			data:{
				"comId":comId
			},
			cache:false,    
			dataType:'json',  
			success: function(data){
				//var list = data.list;
				var list =  eval('(' + data.list + ')');
				var option2 = '<option value="">请选择票务室</option>';
				$("#toId").append(option2);
				for(var i=0;i<list.length;i++){
					var option = '<option value="'+list[i].toiid+'">'+list[i].toiname+'</option>';
					$("#toId").append(option);
				}
			},
			error:function(){
				alert("请求失败");
			}
		});
	});
	
	$("#tickets").change(function(){
		
	})
	
	
	
	// $.ajax({
	// 	type: 'POST',
	// 	url: abnormalreport_service+'office/getAllCompany',
	// 	dataType: 'json',
	// 	async: false,
	// 	success: function(data){
	// 	//	var list =  eval('(' + data.list + ')');
	// 	var list =data.officeList;
	// 	for(var i=0;i<list.length;i++){
	// 		var option = '<option value="'+list[i].officename+'">'+list[i].officename+'</option>';
	// 		$("#rallyingPoint").append(option);
	// 	}
			
	// 	},
	// 	error: function(data){
	// 		console.log(data.msg);
	// 	}
	// });

	$("#toId").change(function(){
		$("#rallyingPoint").empty();
		var officeId = $(this).val();
		var targetUrl = abnormalreport_service+'office/queryOfficeAll';
		if(officeId == ''){
			//$("#toId").fadeOut("slow");
			return;
		}
		$.ajax({
			type: 'get',
			url: targetUrl,
			data:{
				"officeId":officeId
			},
			cache:false,    
			dataType:'json',  
			success: function(data){
				var list = data.list;
				//var list =  eval('(' + data.list + ')');
			//	var option2 = '<option value="">请选择票务室</option>';
			//	$("#rallyingPoint").append(option2);
				for(var i=0;i<list.length;i++){
					console.log(list[i])
					// if("1"==list[i].officetype){
					// 	$("#divSpan").attr("style", "display:blank;");
					// }
					var option = '<option value="'+list[i].rallyingPoint+'">'+list[i].rallyingPoint+'</option>';
					$("#rallyingPoint").append(option);
				}
			},
			error:function(){
				alert("请求失败");
			}
		});
	});
	

	

</script>
</body>
</html>